﻿using AutoMapper;
using FreeSqlDemo.Services;
using Magicodes.IE.Demo.Common;
using Magicodes.IE.Demo.Dto;
using Magicodes.IE.Demo.IService;
using Magicodes.IE.Demo.Modules;
using Microsoft.AspNetCore.Mvc;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Threading.Tasks;

namespace Magicodes.IE.Demo.Service
{
    public class ExportServices : IExportServices
    {
        private readonly IMapper _mapper;
        public ExportServices(IMapper mapper)
        {
            _mapper = mapper;
        }
        /// <summary>
        /// 数组导出
        /// </summary>
        /// <returns></returns>
        //public Task<ActionResult> ByBytes()
        //{
        //    throw new NotImplementedException();
        //}
        /// <summary>
        /// 泛型导出
        /// </summary>
        /// <returns></returns>
        public ActionResult ByListAsync()
        {
            var student = FerrSQL.fsql.Select<Student>().ToList();
            var list = _mapper.Map<List<ImportStudentDto>>(student);
            //var list = GenFu.GenFu.ListOf<ImportUserInfoDto>(2); 随机生成数据
            return new XlsxFileResultT<ImportStudentDto>(data: list, "下载文件");
        }
        /// <summary>
        /// 流式导出
        /// </summary>
        /// <returns></returns>
        //public Task<ActionResult> ByStream()
        //{
        //    throw new NotImplementedException();
        //}
    }
}
